package com.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chen.dao.mapper.AlbumMapper;
import com.chen.dao.mapper.SystemSettingMapper;
import com.chen.dao.pojo.Album;
import com.chen.dao.pojo.SystemSetting;
import com.chen.service.SystemService;
import com.chen.vo.AlbumVo;
import com.chen.vo.Result;
import com.chen.vo.system.SwiperVo;
import java.lang.invoke.LambdaConversionException;
import java.util.LinkedList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author:chenao
 * @DATE:2022/3/5 14:36
 */
@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    private SystemSettingMapper systemMapper;
    @Autowired
    private AlbumMapper albumMapper;

    @Override
    public Result listSwiper() {
        List<SystemSetting> systemSettings = systemMapper.selectList(null);
        List<SwiperVo> voList = new LinkedList<>();
        systemSettings.stream().forEach(item->{
            SwiperVo swiperVo = new SwiperVo();
            swiperVo.setId(item.getId());
            swiperVo.setImageUrl(item.getImageUrl());
            voList.add(swiperVo);
        });
        return Result.success(voList);
    }

    @Override
    public Result listAlbum() {
        List<Album> albums = albumMapper.selectList(null);
        List<AlbumVo> albumVoList = new LinkedList<>();
        albums.stream().forEach(item->{
            AlbumVo albumVo = new AlbumVo();
            BeanUtils.copyProperties(item,albumVo);
            albumVo.setImageUrl(item.getImageUrl());
            albumVoList.add(albumVo);
        });
        return Result.success(albumVoList);
    }
}
